<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>问题列表</title>
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script type="text/javascript">
	
</script>
<style type="text/css">
body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.deepDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.normalDark {
	
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}
</style>
<script type="text/javascript">
	var stateData = [ {
		id : 1,
		text : "婚姻家庭"
	}, {
		id : 2,
		text : "交通事故"
	}, {
		id : 3,
		text : "继承纠纷"
	}, {
		id : 4,
		text : "刑事辩护"
	}, {
		id : 5,
		text : "劳动仲载"
	}, {
		id : 6,
		text : "消费权益"
	}, {
		id : 7,
		text : "房屋拆迁"
	}, {
		id : 8,
		text : "债权债务"
	}, {
		id : 0,
		text : "其他问题"
	} ];
	var typeData = ["其他问题","婚姻家庭","交通事故","继承纠纷","刑事辩护","劳动仲载","消费权益","房屋拆迁","债权债务"];
</script>
</head>
<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td><a class="mini-button" id="rebackBtn" plain="true"
					iconCls="icon-list" onclick="status1">返回列表</a> <a
					class="mini-button" id="checkBtn" iconCls="icon-magDetail"
					plain="true" onclick="checkRecord">查看</a> <a class="mini-button"
					id="resetBtn" iconCls="icon-reset" plain="true"
					onclick="reloadList">刷新</a>
				<span class="separator"></span>&nbsp;&nbsp;查询日期:&nbsp;&nbsp;<input
					id="starting" class="mini-combobox" style="width: 100px;"
					showNullItem="false" textField="CREATEDATE" 
					url="<c:url value='/questionMng/date' />"
					valueField="CREATEDATE" onvalidation="" allowInput="false"
					emptyText="起始期间..." nullItemText="&lt;无&gt;" onvaluechanged="startingSelect" />
					<span
					style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
					<input id="ending" class="mini-combobox" style="width: 100px;"
					showNullItem="false" textField="CREATEDATE"
					url="<c:url value='/questionMng/date' />"
					valueField="CREATEDATE" onvalidation="" allowInput="false"
					emptyText="截止期间..." nullItemText="&lt;无&gt;" onvaluechanged="endingSelect" />
					<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
					onclick="onselect" tooltip="统计" plain="true">统计</a></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px;">
				<div class="mini-fit">
					<div id="datagrid1" class="mini-datagrid gridFull"
						borderStyle="border:1;" showReloadButton="true" pagesize="100"
						sizeList="[20,50,100,200]" allowCellWrap="true"
						allowHeaderWrap="true" idField="No" multiSelect="true"
						showPager="true" allowAlternating="true"
						ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
						style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
						collapseGroupOnLoad="false" showColumnsMenu="true"
						showFilterRow="true" onshowrowdetail="onShowRowDetail">
						<div property="columns">
							<div type="indexcolumn" width="40px"></div>
							<div field="Action" width="70px" headerAlign="center"
								align="center">
								<a class="mini-button" property="filter" id="removeBtn"
									iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
								</a>
							</div>
							<div field="CREATEUSER" width="100px" headerAlign="center"
								align="left" allowSort="true">
								提问人<input id="filter0" property="filter"
									class="mini-buttonedit searchbox" style="width: 100%;"
									onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
							</div>
							<div field="NICKNAME" width="100px" headerAlign="center"
								align="left" allowSort="true">
								昵称<input id="filter1" property="filter"
									class="mini-buttonedit searchbox" style="width: 100%;"
									onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
							</div>
							<div field="QUESTIONTYPEID" width="100px" headerAlign="center"
								align="center" allowSort="true">
								问题类型<input id="filter2" property="filter" class="mini-combobox"
									style="width: 100%;" onitemclick="onselect" emptyText="所有"
									showNullItem="true" data=stateData />
							</div>
							<div field="CONTENT" width="400px" headerAlign="center"
								align="left">
								问题详细<input id="filter3" property="filter"
									class="mini-buttonedit searchbox" style="width: 100%;"
									onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
							</div>
							<!-- <div name="answerCount" field="LS" width="80px" headerAlign="center"
								align="left" allowSort="true">回答数</div> -->
							<div field="CREATETIME" width="85px" dateFormat="yyyy-MM-dd"
								headerAlign="center" align="center" allowSort="true">提问日期</div>
							<div name="emptyCol" width='100%' headerAlign="center"
								align="center" cellStyle="padding:0;"></div>
						</div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="frameContnt" class="subPageFrame" frameborder="0"></iframe>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';

		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var splitpan = mini.get("splitterPan");
		var starting = mini.get("starting");
		var ending = mini.get("ending");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		//双击
		function gridRowDbClick(e) {
			var id = e.row.ID;
			var phoneNo = e.row.CREATEUSER;
			showDetail(id,phoneNo);
		}
		function showDetail(id,phoneNo) {
			status2();
			if (!id) {
				mini.alert('这条数据有误，请联系管理员处理。');
				return;
			}
			$('#frameContnt').css('height', '100%').css('width', '100%').attr(
					'src',
					'<c:url value="/questionMng/detail/" />' + id+'/'+phoneNo);
		}
		function onselect() {
			filterHelper.clearFilterData();
			var startStr = starting.getValue();
			var endStr = ending.getValue();
			if(startStr && endStr && startStr > endStr){
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (startStr) {
				var filterdata = filterHelper.formFilterData("CREATETIME",
						startStr, '', 'GREATER_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (endStr) {
				var endTime = new Date(endStr);
				var tempTime = endTime.valueOf();
				tempTime += 24*60*60*1000;
				endTime = new Date(tempTime);
				var year = endTime.getYear()+1900;
				var month = endTime.getMonth()+1;
				if(month < 10){
					month = "0"+month;
				}
				var day = endTime.getDate();
				if(day < 10){
					day = "0"+day;
				}
				endStr = year+"-"+month+"-"+day;
				var filterdata = filterHelper.formFilterData("CREATETIME",
						endStr, '', 'LESS_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			
			var filterValue0 = filter0.getValue();
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("CREATEUSER",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("CREATEUSER",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("QUESTIONTYPEID",
						filterValue2, '', 'EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("CONTENT",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			
			loadGrid1();
		}
		function dateAdd(){
			
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/questionMng/listData' />";
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			starting.setValue();
			ending.setValue();
			filter0.setValue();
			filter0.setText();
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;

			if (field == "Action") {
				var id = row.ID;
				var phoneNo = row.CREATEUSER;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail(\'' + id
						+'\',\''+phoneNo+ '\')">[查看]</a>';
			} 

			if(field == "QUESTIONTYPEID"){
				var value = e.value;
				e.cellHtml = typeData[value];
			}
			if(field == "NICKNAME"){
				var value = e.value;
				if(!value){
					e.cellHtml = row.CREATEUSER;
				}
			}
		}
		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#checkBtn').show();
			$('#resetBtn').show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#checkBtn').hide();
			$('#resetBtn').hide();
		}
		function status3Show() {
			$('#rebackBtn').hide();
			$('#checkBtn').show();
			$('#resetBtn').show();
		}
		function checkRecord() {
			var rows = datagrid1.getSelecteds();
			var length = rows.length;
			if (length == 0) {
				mini.alert("请选择一条记录.");
				return;
			} else if (length == 1) {
				var id = rows[0].ID;
				var phoneNo = rows[0].CREATEUSER;
				showDetail(id,phoneNo);
			} else {
				mini.alert("只能选择一条记录.");
				return;
			}
		}
		/* 开始日期选择 */
		function startingSelect(){
			var startStr = starting.getValue();
			var endStr = ending.getValue();
			if(endStr && startStr > endStr){
				mini.alert('开始日期不能大于结束日期！');
				starting.setValue();
				return;
			}
		}
		/* 结束日期选择 */
		function endingSelect(){
			var startStr = starting.getValue();
			var endStr = ending.getValue();
			if(!endStr){
				return;
			}else if(!startStr){
				mini.alert('请先选择开始日期！');
				ending.setValue();
				return;
			}else if(startStr > endStr){
				mini.alert('结束日期不能小于开始日期！');
				ending.setValue();
				return;
			}
		}
		function search(){
			var startStr = starting.getValue();
			var endStr = ending.getValue();
			if(!startStr){
				mini.alert('开始日期不能为空！');
				return;
			}else if(!endStr){
				mini.alert('结束日期不能为空！');
				return;
			}else if(startStr > endStr){
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			
			
			var filterdata1 = filterHelper.formFilterData("CREATETIME",
					startStr, '', 'GREATER_EQUALS', 'AND');
			var filterdata2 = filterHelper.formFilterData("CREATETIME",
					endStr, '', 'LESS_EQUALS', 'AND');
			filterHelper.addFilterData(filterdata1);
			filterHelper.addFilterData(filterdata2);
			loadGrid1();
		}
		function reloadList() {
			datagrid1.reload();
		}
	</script>
</body>
</html>